package edu.ustb.railwayticket.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;

import java.util.UUID;

public class EurekaConfigBeanPostProcessor implements BeanPostProcessor {

    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof EurekaInstanceConfigBean) {
            EurekaInstanceConfigBean properties = (EurekaInstanceConfigBean) bean;
            String instanceId = properties.getInstanceId();
            System.out.println("Old InstanceID:    " + instanceId);
            instanceId = UUID.randomUUID().toString();

            //修改ID
            properties.setInstanceId(instanceId);
        }
        return null;
    }

}
